home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / netid.zip / NETID8.ASM < prev    next >
Assembly Source File  |  1992-09-03  |  14KB  |  367 lines

  1. ;
  2. ; Simple program to extract the user's name from netware and place it in
  3. ; an environment variable "USER".  
  4. ;
  5. ; Public Domain - credits to Matthew Staben, Staben Technologies
  6. ;                                            811 West 14th Avenue
  7. ;                                            Spokane, WA  99204
  8. ;
  9.  
  10.  
  11.  
  12.  
  13. .model small
  14. .code
  15.  
  16.                 ;===============================:
  17.                 ; first, test for MS-DOS or 4DOS:
  18.                 ;===============================:
  19.                 mov     ax, 0D44Dh              ; 4DOS swap area
  20.                 mov     bx, 0
  21.                 int     2Fh                     ; and interrupt it
  22.                 ;===============================:
  23.                 ;IF ax = 44DD, 4DOS is used.    :
  24.                 ;===============================:
  25.                 cmp     ax, 44DDh               ; compare the deal
  26.                 je      IS_4DOS                 ; and if equal, its 4DOS
  27.                 mov     ax, 352Eh               ; find the master env
  28.                 int     21h
  29.                 mov     es, [es:2Ch]            ; es = environment segment
  30.                 jmp     short   dos_checked     ; jump past 4dos stuff
  31.         is_4dos:
  32.                 mov     es, cx                  ; es = 4dos environment segment
  33.                 mov     es, [es:2Ch]
  34.         dos_checked:            
  35.                 mov     [cs:envseg], es
  36.                 xor     di, di                  ; point to start of env in es:di
  37.                 cld                             ; scan in forward
  38. FIND_STRING:                                    ; - loop thru 1 by 1
  39.                 test    [byte ptr es:[di]], -1  ; end of env?
  40.                 jnz     check_string            ; nope... continue
  41.                 jmp     short   no_environment  ; error...
  42. CHECK_STRING:           
  43.                 push    cs
  44.                 pop     ds
  45.                 mov     si, offset ENVSTR       ; point to USERNAME
  46.                 mov     bx, di                  ; save ptr to start
  47.                 mov     cx, envlen              ; length of envstr
  48.                 repe    cmpsb                   ; compare
  49.                 je      ALL_PASSED              ; found it!
  50.                 mov     di, bx                  ; restore ptr to start
  51.                 xor     al, al                  ; scan for end of string
  52.                 mov     cx, -1                  ; FFFF <- cx
  53.                 repne   scasb
  54.                 jmp     short   find_string     ; go back for next string
  55.                 
  56. ALL_PASSED:
  57.                 mov     [cs:envoff], di
  58.                 clc
  59.                 mov     [cs:onezero], 0
  60.                 jmp     BEGIN
  61.                 
  62. NO_ENVIRONMENT:
  63.                 ;===========================:
  64.                 ; This procedure is called  :
  65.                 ; if the environment string :
  66.                 ; does not exist.           :
  67.                 ;===========================:
  68.                 ; so, create it!            :
  69.                 ;===========================:
  70.                 
  71.                 mov     [cs:onezero],2
  72.                 mov     ax, [cs:envseg]
  73.                 mov     es, ax
  74.                 xor     di, di
  75.                 
  76.                 ; look for pair of zeros, the second zero is the new begin
  77. lookfor:                
  78.                 mov     ah, [byte ptr es:[di]]
  79.                 cmp     ah, 0
  80.                 je      first_zero
  81.                 inc     di
  82.                 jmp     lookfor
  83. first_zero:
  84.                 inc     di
  85.                 mov     ah, [byte ptr es:[di]]
  86.                 cmp     ah, 0
  87.                 jne     lookfor
  88.                 
  89. is_zero:
  90.                 mov     [byte ptr es:[di]], 85
  91.                 inc     di
  92.                 mov     [byte ptr es:[di]], 83
  93.                 inc     di
  94.                 mov     [byte ptr es:[di]], 69
  95.                 inc     di
  96.                 mov     [byte ptr es:[di]], 82
  97.                 inc     di
  98.                 mov     [byte ptr es:[di]], 61    
  99.                 inc     di
  100.                 mov     [cs:envoff], di
  101.                 jmp     begin
  102.  
  103. SHOW_MESSAGE:
  104.                 mov     ah, 09h
  105.                 int     21h
  106.                 
  107. EXIT_OUT:
  108.                 jmp     bye_bye
  109. BEGIN:
  110.  
  111. MODIFY_ENV:
  112.                 ;==================================================:
  113.                 ; Let's get the username and slip into the env     :
  114.                 ;==================================================:
  115.                 
  116.                 mov     AH,0DCh                 ; function to get connection #
  117.                 int     21h
  118.                 mov     CS:ConnectionNumber,AL
  119.  
  120.                 mov     AH,0E3h                 ; log request function #
  121.  
  122.                 mov     DX,seg cs:RequestBuffer
  123.                 mov     DS,DX
  124.                 mov     DX,seg cs:ReplyBuffer
  125.                 mov     ES,DX
  126.                 lea     SI,cs:RequestBuffer        ;  DS:SI points to Request Buffer
  127.                 lea     DI,cs:ReplyBuffer          ;  ES:DI points to Reply Buffer
  128.                                               
  129.                 int     21h
  130.  
  131. ;  Return the name
  132.  
  133.        WRITE_OUT:
  134.                 ; here, we actually write out the environment.       
  135.                 mov     ax, seg cs:objectname
  136.                 mov     es, ax
  137.                 mov     di, offset cs:objectname
  138.                 mov     [cs:objectoff], di
  139.                 mov     [cs:objectseg], es
  140.                 mov     ax, cs
  141.                 mov     ds, ax
  142.                 mov     si, offset safearea
  143.                 xor     dx, dx
  144.                 xor     bx, bx
  145.                 xor     cx, cx
  146.                 
  147.                 cmp     [cs:onezero], 2
  148.                 jne     REPLACEUPTO
  149.                 
  150.                 ; 
  151.                 ; just fill it out and add two zeros
  152.                 ;
  153.           APPEND:
  154.                 mov     es, [cs:objectseg]
  155.                 mov     di, [cs:objectoff]
  156.                 mov     ah, [byte ptr es:[di]]
  157.                 cmp     ah, 0
  158.                 je      addtwo
  159.                 cmp     [cs:charcount], 8
  160.                 je      addtwo
  161.                 inc     [cs:objectoff]
  162.                 inc     [cs:charcount]
  163.                 mov     es, [cs:envseg]
  164.                 mov     di, [cs:envoff]
  165.                 inc     [cs:envoff]
  166.                 mov     [byte ptr es:[di]], ah
  167.                 jmp     append
  168.       addtwo:
  169.                 mov     es, [cs:envseg]
  170.                 mov     di, [cs:envoff]
  171.                 jmp     addtwozeros
  172.  
  173.       samelength:
  174.                 cmp     ah, 0
  175.                 jne     retsame
  176.                 jmp     did_it
  177.                                 
  178.       REPLACEUPTO:
  179.                 ; 
  180.                 ; replace the environment up to the first zero
  181.                 ;
  182.                 mov     es, [cs:objectseg]
  183.                 mov     di, [cs:objectoff]
  184.                 mov     ah, [byte ptr es:[di]]  ; next net buffer char
  185.                 mov     es, [cs:envseg]
  186.                 mov     di, [cs:envoff]
  187.                 mov     al, [byte ptr es:[di]]
  188.                 ; check if both are zero
  189.                 cmp     al, ah
  190.                 je      samelength
  191.            retsame:
  192.                 ; check if zero has been reached in environment
  193.                 cmp     al, 0
  194.                 je      ENDREPLACE
  195.                 ; check if zero has been reached in net-buffer
  196.                 cmp     ah, 0
  197.                 je      ENDNETBUF
  198.                 ; check if 8 chars have been used
  199.                 cmp     [cs:charcount], 8
  200.                 je      ENDNETBUF
  201.                 inc     [cs:charcount]
  202.                 mov     es, [cs:envseg]
  203.                 mov     di, [cs:envoff]
  204.                 mov     [byte ptr es:[di]], ah
  205.                 inc     [cs:envoff]
  206.                 inc     [cs:objectoff]
  207.                 jmp     REPLACEUPTO
  208.  
  209.       ENDNETBUF:
  210.                 ; 
  211.                 ; scan thru environment to next char, saving the current
  212.                 ; position in the environment for replacing
  213.                 ;
  214.                 mov     es, [cs:objectseg]
  215.                 mov     di, [cs:objectoff]
  216.                 mov     [byte ptr es:[di]], 0
  217.                 mov     es, [cs:envseg]
  218.                 mov     di, [cs:envoff]
  219.                 mov     [cs:startpos], di
  220.                 ; find a zero
  221.          envscan:
  222.                 inc     di
  223.                 mov     ah, [byte ptr es:[di]]
  224.                 cmp     ah, 0
  225.                 je      endenvscan
  226.                 jmp     envscan
  227.          endenvscan:
  228.                 mov     [cs:envoff], di
  229.                 
  230.       ENDREPLACE:
  231.                 ; 
  232.                 ; save the rest of the environment in the buffer
  233.                 ;
  234.                 mov     di, [cs:envoff]
  235.                 cmp     [cs:startpos], 0
  236.                 jne     checkstart
  237.                 mov     [cs:startpos], di
  238.          checkstart:
  239.                 mov     es, [cs:envseg]
  240.                 mov     di, [cs:envoff]
  241.                 mov     ah, [byte ptr es:[di]]
  242.                 cmp     ah, 0
  243.                 jne     notzero
  244.                 inc     di
  245.                 mov     ah, [byte ptr es:[di]]
  246.                 dec     di
  247.                 cmp     ah, 0
  248.                 je      checkout
  249.          
  250.          notzero:
  251.                 mov     ah, [byte ptr es:[di]]
  252.                 mov     [byte ptr ds:[si]], ah
  253.                 inc     [cs:envoff]
  254.                 inc     si
  255.                 inc     dl
  256.                 jmp     checkstart
  257.       
  258.          checkout:
  259.        
  260.       FILLENVIRONMENT:
  261.                 ; 
  262.                 ; if the buffer was too long, we still have some chars to
  263.                 ; slip into the environment from the network buffer
  264.                 ;
  265.                 mov     es, [cs:objectseg]
  266.                 mov     di, [cs:objectoff]
  267.                 mov     ah, [byte ptr es:[di]]
  268.                 cmp     ah, 0
  269.                 je      fillitup
  270.                 cmp     [cs:charcount], 8
  271.                 je      fillitup
  272.            fillnet:
  273.                 mov     es, [cs:objectseg]
  274.                 mov     di, [cs:objectoff]
  275.                 mov     ah, [byte ptr es:[di]]
  276.                 cmp     ah, 0
  277.                 je      fillitup
  278.                 cmp     [cs:charcount], 8
  279.                 je      fillitup
  280.                 inc     [cs:objectoff]
  281.                 mov     es, [cs:envseg]
  282.                 mov     di, [cs:startpos]
  283.                 mov     [byte ptr es:[di]], ah
  284.                 inc     [cs:startpos]
  285.                 inc     [cs:charcount]
  286.                 jmp     fillnet
  287.                 
  288.            fillitup:
  289.                 mov     di, [cs:startpos]
  290.                 mov     [cs:envoff], di
  291.                 mov     ax, cs
  292.                 mov     ds, ax
  293.                 mov     si, offset safearea
  294.                 inc     dl
  295.            filloop:
  296.                 mov     di, [cs:envoff]
  297.                 mov     es, [cs:envseg]
  298.                 mov     ah, [byte ptr ds:[si]]
  299.                 inc     si
  300.                 mov     [byte ptr es:[di]], ah
  301.                 inc     [cs:envoff]
  302.                 inc     cx
  303.                 cmp     cx, dx
  304.                 je      addtwozeros
  305.                 jmp     filloop
  306.          
  307.            addtwozeros:
  308.                 mov     [byte ptr es:[di]], 0
  309.                 inc     di
  310.                 mov     [byte ptr es:[di]], 0
  311.  
  312. did_it:
  313.                 mov     ax, cs
  314.                 mov     ds, ax
  315.                 mov     dx, offset ACTION      ; point to finished mssg
  316.                 jmp     show_message
  317.         
  318. bye_bye:
  319.                 mov     ah, 4Ch
  320.                 int     21h             
  321.                 
  322. ACTION          DB      0Ah,0Dh,0Ah,0Dh
  323.                 DB      'Bovay Northwest, Inc.', 0Ah, 0Dh
  324.                 DB      '---------------------', 0Ah, 0Dh
  325.                 DB      'Netware Username Extraction Facility',0Ah,0Dh
  326.                 DB      0Ah,0Dh
  327.                 DB      'The currently logged in user''s name ',0Ah,0Dh
  328.                 DB      'has been extracted to the environment',0Ah,0Dh
  329.                 DB      'under USER.',0Ah,0Dh
  330.                 DB      'Any Usernames over 8 characters have',0Ah,0Dh
  331.                 DB      'been truncated.',0Ah,0Dh
  332.                 DB      0AH,0Dh
  333.                 DB      '$'
  334.  
  335. ;============================================:
  336. ; Variables which are internally used by the :
  337. ; program.                                   :
  338. ;============================================:
  339. safearea        DB      512 dup ( ? )          ; temp storage buffer
  340. EMPTYSPOT       DB      'D'
  341. ENVSTR          DB      'USER='                 ; Env. variable to find
  342. ENVLEN          EQU     5                       ; length of env variable
  343. envseg          DW      0                        ; environment seg
  344. envoff          DW      0                        ; environment offset
  345. objectseg       DW      0                       ; object segment
  346. objectoff       DW      0                       ; object offset
  347. startpos        DW      0                       ; network buffer too short
  348. onezero         DB      0                       ; was it appended?
  349. charcount       DB      0                       ; count of chars
  350.  
  351.  
  352. RequestBuffer           Label   Byte
  353. PacketLengthLow         db      2               ; request buffer 2 bytes long
  354. PacketLengthHigh        db      0
  355. Function                db      22              ; sub function to get user info
  356. ConnectionNumber        db      ?               ; logical connection number
  357.  
  358. ReplyBuffer             Label   Byte
  359. ReturnLengthLow         db      62              ; Reply is 62 bytes long
  360. ReturnLengthHigh        db      0
  361. UniqueID                dd      ?               ; Station's ID #
  362. Typex                   dw      ?
  363. ObjectName              db      48 dup ( ? )    ; USERNAME 1-47 characters
  364. LogTime                 db      8  dup ( ? )    ; Time user logged in
  365.  
  366. end                
  367.